package twentytwenty;

import java.util.*;

/**
 * @Author: Zahi
 * @Description:
 * @Date Created in 2020-12-14 9:29
 * @Modified By:
 */
public class FindTheDifference_389 {
    public static void main(String[] args) {
        String s = "abcdefg", t = "cbadfegt";
        System.out.println(findTheDifference(s, t));
    }

    public static char findTheDifference(String s, String t) {
        List<Character> sArr = new ArrayList<>();
        List<Character> tArr = new ArrayList<>();

        char[] chars = s.toCharArray();
        char[] chart = t.toCharArray();

        for (char aChar : chars) {
            sArr.add(aChar);
        }

        for (char c : chart) {
            tArr.add(c);
        }

        for (int i = 0; i < tArr.size(); i++) {
            int count = 0;
            Character remove = tArr.remove(0);
            List<Character> copy = new ArrayList<>();
            for (char aChar : chars) {
                copy.add(aChar);
            }
            for (int j = 0; j < tArr.size(); j++) {
                if (copy.contains(tArr.get(j))){
                    for (int k = 0; k < copy.size(); k++) {
                        if (copy.get(k) == tArr.get(j)){
                            copy.set(k,'-');
                            break;
                        }
                    }
                    count++;
                }
            }
            if (count == sArr.size()){
                return remove;
            }else {
                tArr.add(remove);
            }
        }
        return 'a';
    }

    public char findTheDifference1(String s, String t) {
        Map<Character, Integer> hss = new HashMap<>();
        Map<Character, Integer> hst = new HashMap<>();

        for(int i = 0; i < s.length(); ++i) {
            hss.put(s.charAt(i), hss.getOrDefault(s.charAt(i), 0) + 1);
        }

        for(int i = 0; i < t.length(); ++i) {
            hst.put(t.charAt(i), hst.getOrDefault(t.charAt(i), 0) + 1);
        }

        for(char i = 'a'; i <= 'z'; i++) {
            if(hss.get(i) != hst.get(i)) {
                return i;
            }
        }
        return ' ';
    }
}
